package examinee;

import utils.Var;
import utils.PageUtils;
import utils.SessionVar;

import java.util.List;
import java.sql.Connection;

import interceptor.InjectConnection;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: Shawn
 * Date: 2009-6-13
 * Time: 21:54:13
 */
public class SearchAction {

  private Connection con;

  @InjectConnection
  public void setCon(Connection con) {
    this.con = con;
  }

  private SearchInfo searchInfo;
  private List<ExamineeInfo> elist;
  private int page;
  private long pageSum;
  private long sum;

  public String getExaminees() throws Exception {
    HttpSession session = ServletActionContext.getRequest().getSession();
    if (searchInfo == null) searchInfo = (SearchInfo) session.getAttribute(SessionVar.EXAMINEE_SEARCH_INFO);
    else session.setAttribute(SessionVar.EXAMINEE_SEARCH_INFO, searchInfo);

    sum = Examinee.getExamineeSum(con, searchInfo);
    pageSum = sum / Var.PAGE_LENGTH + 1;
    page = PageUtils.getPage(page);
    long from = PageUtils.getFrom(page);

    elist = Examinee.getExamineeList(con, searchInfo, from, Var.PAGE_LENGTH);
    return Var.ACTION_SUCCESS;
  }

  public SearchInfo getSearchInfo() {
    return searchInfo;
  }

  public void setSearchInfo(SearchInfo searchInfo) {
    this.searchInfo = searchInfo;
  }

  public List<ExamineeInfo> getElist() {
    return elist;
  }

  public void setPage(int page) {
    this.page = page;
  }

  public int getPage() {
    return page;
  }

  public long getPageSum() {
    return pageSum;
  }

  public long getSum() {
    return sum;
  }

  private List<String> plist;

  public String getPxjgs() throws Exception {
    plist = Examinee.getPXJGList(con);
    return Var.ACTION_SUCCESS;
  }

  public List<String> getPlist() {
    return plist;
  }
}
